package com.game.Components;

import com.pixels.Display;
import com.pixels.graphics.*;
import com.Math.*;

public class Bullet {

	public Vector2D pos;
	Vector2D start;
	Vector2D leng;
	double dir;
	double speed = 10;
	int ticksAlive = 0;

	public Bullet(Vector2D v, double dir) {
		start = new Vector2D(v);
		pos = new Vector2D(v);
		pos.x -= Math.cos(dir) * speed;
		pos.y -= Math.sin(dir) * speed;
		this.dir = dir;
	}

	public void move() {
		pos.x -= Math.cos(dir) * speed;
		pos.y -= Math.sin(dir) * speed;
		leng = new Vector2D(start);
		leng.subtract(pos);
		boundaries();
		ticksAlive++;
	}

	public void draw(Drawer draw) {
		draw.setColor(0xff0000);
		draw.sirkel3((int) pos.x, (int) pos.y,3);
	}

	public void destroy() {
		pos.x = 0;
		pos.y = 0;
		speed = 0;
	}

	private void boundaries() {
		if (pos.x > Display.WIDTH) {
			pos.x = 0;
		} else if (pos.x < 0) {
			pos.x = Display.WIDTH;
		}
		if (pos.y > Display.HEIGHT) {
			pos.y = 0;
		} else if (pos.y < 0) {
			pos.y = Display.HEIGHT;
		}
	}
}
